<template>
  <basic-container v-loading="loading">
    <div class="el-page-header haruyuki-mb-20">
      <div
        class="el-page-header__left haruyuki-flex-center haruyuki-size-18"
        @click="goBackPage"
      >
        <i class="el-icon-arrow-left"></i>
        <div class="haruyuki-size-16">返回</div>
      </div>
      <div class="el-page-header__content">{{ $route.name }}</div>
    </div>
    <section class="merchant-container">
      <active-form :activeForm="activeData" ref="toActiveForm" />
      <div class="haruyuki-flex-x-end haruyuki-mt-20 haruyuki-mb-40">
        <el-button size="medium" @click="goBackPage">返 回</el-button>
        <el-tooltip content="提交设备活动配置" placement="top">
            <el-button icon="el-icon-check" size="small" type="primary" v-preventClick @click="handleConfirm">提 交</el-button>
        </el-tooltip>
      </div>
    </section>
  </basic-container>
</template>

<script>
import {
  add,
} from "@/api/rb-oem/active/active";

import activeForm from "../component/active_form.vue";
export default {
  components: {
    activeForm,
  },
  data() {
    return {
      loading: false,
      activeType: '',
      activeCode: '',
      aisleCode: '',
      activeData: {
        activeCode: "",
        activeCount: 0,
        activeName: "",
        aisleCodeList: [],
        beginTime: "",
        debtFake: {
          // debtAmount: 0,
          // examineAmount: 0,
          // period: 0
        },
        debtNone: {
          // debtAmount: 0,
          // period: 0
        },
        endTime: "",
        equipmentTypeList: [],
        examineType: 0,
        limitFormList: [
          {
            activeGrade: 0,
            beginPeriod: 0,
            endPeriod: 0,
            validAmount: 0,
            validCount: 0
          }
        ],
        payTypeList: [],
        period: 0,
        remark: "",
        rpiTypeList: [],
        validAmount: 0,
        validCount: 0
      }
    };
  },
  created() {
    if (this.$route.query.activeCode) {
      this.activeType = 'edit';
      this.activeCode = this.$route.query.activeCode;
      this.$nextTick(()=>{
        this.$refs["toActiveForm"].getActiveDetails(this.activeCode);
      })
    } else {
      this.activeType = 'add';
    }
  },
  methods: {
    /**
     * @func 商户信息确认
     * @desc 商户信息(变更/修改)确认
     * */
    handleConfirm() {
      // let type = '';
      // if (this.rpiNo) type = 'add';
      // if (this.changeNo) type = 'edit';
      this.$refs["toActiveForm"].$refs["activeForm"].validate((valid) => {
        if (valid) {
          
          add(this.$refs["toActiveForm"].activeForm).then(
            (res) => {
              if (res.data.code === 200) {
                this.$message({
                  type: "success",
                  message: "设备活动配置已提交!",
                });
                this.goBackPage();
              }
            },
            (error) => {
              window.console.log(error);
            }
          );
        } else {
          return false;
        }
      });
    },
    /**
     * @func dialog商户信息取消
     * @desc dialog商户信息(变更/修改)取消
     * */
    handleCancel() {
      //   this.dialogVisible = false;
      this.emptyForm();
    },
    /**
     * @func 清空
     * @desc OEM表单信息 清空
     * */
    emptyForm() {
      this.$refs["toAlterForm"].$refs["alterInfo"].resetFields();
      this.$refs["toAlterForm"].basicForm = {};
      this.$refs["toAlterForm"].accountFrontList = [];
      this.$refs["toAlterForm"].accountReverseList = [];
      this.$refs["toAlterForm"].openPermitList = [];
      this.$refs["toAlterForm"].ecardFrontList = [];
      this.$refs["toAlterForm"].ecardReverseList = [];
    },
    /* 返回页面 */
    goBackPage() {
      this.$router.$avueRouter.closeTag();
      this.$router.back();
    },
  },
};
</script>

<style>
</style>